import os
from mutagen.mp3 import MP3
from moviepy.editor import VideoFileClip

def get_mp3_info(file_path):
    try:
        audio = MP3(file_path)
        info = {
            'title': audio.tags.get('TIT2', 'Unknown'),
            'artist': audio.tags.get('TPE1', 'Unknown'),
            'album': audio.tags.get('TALB', 'Unknown'),
            'duration': audio.info.length,
        }
        return info
    except Exception as e:
        return str(e)

def get_mp4_info(file_path):
    try:
        video = VideoFileClip(file_path)
        info = {
            'duration': video.duration,
            'fps': video.fps,
            'width': video.w,
            'height': video.h,
        }
        video.close()
        return info
    except Exception as e:
        return str(e)

def get_file_info(file_path):
    if not os.path.exists(file_path):
        return "File not found"

    file_extension = os.path.splitext(file_path)[1].lower()

    if file_extension == '.mp3':
        return get_mp3_info(file_path)
    elif file_extension == '.mp4':
        return get_mp4_info(file_path)
    else:
        return "Unsupported file format"

# 示例用法
if __name__ == "__main__":
    file_path = input("请输入文件路径: ")
    info = get_file_info(file_path)
    print(info)
